package cn.tedu.api;
/**本类用于测试字符串的拼接*/
public class TestString3 {
    public static void main(String[] args) {
        //需求:将26个字母拼接10000ci
        String s = "abcdefghijklmnopqrstuvwxyz";
        System.out.println(s.length());
//        method1(s);
        method2(s);

    }

    private static void method2(String s) {
        //创建一个变量用来保存拼接后的效果
        String result = "";
        //1.创建工具类对象
//        StringBuffer sb = new StringBuffer();
        StringBuilder sb2 = new StringBuilder();
        //2.拼接一万次
        long t1 = System.currentTimeMillis();
        System.out.println(t1);
        for (int i = 0; i < 10000; i++) {
            sb2.append(s);

        }
        System.out.println(sb2);
        long t2 = System.currentTimeMillis();
        System.out.println(t2);
        System.out.println(t2-t1);
    }


    private static void method1(String s) {
        String result = "";
        //5.给程序添加一个记时间的功能
        //5.1获取循环开始时的系统的当前时间作为开始时间
        long t1 = System.currentTimeMillis();
        System.out.println(t1);
        for (int i = 0; i < 10000; i++) {
            result = result +s;
        }
        System.out.println(result);
        long t2 = System.currentTimeMillis();
        System.out.println(t2);
        System.out.println(t2-t1);
    }
}

